<script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件-->
<script type="text/javascript" src="/ueditor/ueditor.all.min.js"></script>


<div class="span10" id="datacontent">
    <ul class="breadcrumb">
        <li><a href="/weixin/product/index">微信399</a> <span class="divider">/</span></li>
        <li class="active">添加内容</li>
    </ul>
    <form action="/weixin/product/add" method="post" class="form-horizontal">
        <!--产品id-->
        <input type="hidden" name="id" value="<?php echo isset($data['id']) ? $data['id'] : ''; ?>"/>
        <fieldset>
            <div class="control-group">
                <label for="modulename" class="control-label">名称</label>
                <div class="controls">
                    <input type="text" id="input1" name="name"
                           value="<?php echo isset($data['name']) ? $data['name'] : '' ?>" datatype="userName"
                           needle="needle" msg="您必须输入名称">
                </div>
            </div>

            <div class="control-group">
                <label for="modulename" class="control-label">科目</label>
                <div class="controls">
                    <input type="text" id="input2" name="section"
                           value="<?php echo isset($data['section']) ? $data['section'] : '' ?>" datatype="userName"
                           needle="needle" msg="您必须输入名称">
                </div>
            </div>

            <div class="control-group">
                <label for="modulename" class="control-label">价格</label>
                <div class="controls">
                    <input type="text" id="input3" name="price"
                           value="<?php echo isset($data['price']) ? $data['price'] : '' ?>" datatype="userName"
                           needle="needle" msg="您必须输入名称">
                </div>
            </div>

            <div class="control-group">
                <label for="moduledescribe" class="control-label">图片</label>

                <div class="controls">
                    <div style="margin-bottom: 10px" id="InputsWrapper">
                                  <span>
                                      <input type="text" class="imageFile" name="image"
                                             value="<?php echo isset($data['image']) ? $data['image'] : '' ?>"
                                             placeholder="图片地址">
                                  </span>
                        <br>
                        <br>
                    </div>
                    <a href="#" class="btn btn-info" onclick="upImage();">上传图片</a>
                </div>
            </div>

            <div class="control-group">
                <label for="modulename" class="control-label">课程介绍</label>
                <div class="controls">
                <textarea id="editor"
                          name="descripition"><?php echo isset($data['descripition']) ? $data['descripition'] : '' ?></textarea>
                    <script>
                        var editor = UE.getEditor('editor', {initialFrameWidth: null});
                    </script>
                </div>
            </div>

            <div class="control-group">
                <label for="modulename" class="control-label">老师介绍</label>
                <div class="controls">
                <textarea id="editor1"
                          name="teacher"><?php echo isset($data['teacher']) ? $data['teacher'] : '' ?></textarea>
                    <script>
                        var editor1 = UE.getEditor('editor1', {initialFrameWidth: null});
                    </script>
                </div>
            </div>

            <div class="control-group">
                <label for="modulename" class="control-label">推流URL</label>
                <div class="controls">
                    <input type="text" id="input4" name="pushUrl"
                           value="<?php echo isset($data['pushUrl']) ? $data['pushUrl'] : '' ?>" datatype="userName"
                           needle="needle" msg="您必须输入名称">
                </div>
            </div>

            <div class="control-group">
                <div class="controls">
                    <input type="submit" class="btn btn-primary" value="提交">
                </div>
            </div>
        </fieldset>
    </form>
</div>


<script>
    //实例化编辑器
    var o_ueditorupload = UE.getEditor('j_ueditorupload',
        {
            autoHeightEnabled: false
        });
    o_ueditorupload.ready(function () {

        o_ueditorupload.hide();//隐藏编辑器

        //监听图片上传
        o_ueditorupload.addListener('beforeInsertImage', function (t, arg) {
            let array = []
            arg.forEach(function (item){
                array.push(item.src)
            })
            $('.imageFile').val(array.toString());
        });

        /* 文件上传监听
         * 需要在ueditor.all.min.js文件中找到
         * d.execCommand("insertHtml",l)
         * 之后插入d.fireEvent('afterUpfile',b)
         */
        o_ueditorupload.addListener('afterUpfile', function (t, arg) {

        });
    });

    //弹出图片上传的对话框
    function upImage() {
        var myImage = o_ueditorupload.getDialog("insertimage");
        myImage.open();
    }

    //弹出文件上传的对话框
    //    function upFiles()
    //    {
    //        var myFiles = o_ueditorupload.getDialog("attachment");
    //        myFiles.open();
    //    }

</script>
<script type="text/plain" id="j_ueditorupload"></script>